
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class SignUpPageEx extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return Navigator(
      initialRoute: 'signup/personal_info',
      onGenerateRoute: (RouteSettings settings){
        WidgetBuilder builder;
        switch(settings.name){
          case 'signup/personal_info':
            builder = (BuildContext context) => const CollectPersionalInfoPage();
            break;
          case 'sign/choose_credentials':
            builder = (BuildContext context) => ChooseCredentialPage(
              onSignupComplete:(){
                Navigator.of(context).pop();
              }
            );
            break;
          default:
            throw Exception('Invalid route:${settings.name}');

        }
        return MaterialPageRoute(builder: builder, settings: settings);
      },
    );
  }
}

class CollectPersionalInfoPage extends StatelessWidget{
  const CollectPersionalInfoPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return DefaultTextStyle(style: Theme.of(context).textTheme.headline4!,
        child: GestureDetector(
          onTap: (){
            Navigator.of(context).pushReplacementNamed('sign/choose_credentials');
          },
          child: Container(
            color: Colors.lightBlue,
            alignment: Alignment.center,
            child: const Text('Collect Personal Info Page'),
          ),
        ));
  }
}

class ChooseCredentialPage extends StatelessWidget{
  const ChooseCredentialPage({
    Key? key,
    required this.onSignupComplete}) : super(key: key);
  final VoidCallback onSignupComplete;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onSignupComplete,
      child: DefaultTextStyle(
        style: Theme.of(context).textTheme.headline4!,
        child: Container(
          color: Colors.pinkAccent,
          alignment: Alignment.center,
          child: const Text('Choose Credentials Page'),
        ),
      ),
    );
  }
}